#include <stdio.h>


int main(void)
{
	unsigned short a,z;
	scanf("%o",&a);
	z=a&0100000;
	if(z==0100000) 	z=~a+1;
	else			z=a;
	printf("%o\n",z);
	return 0;
}